package com.hanqi.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hanqi.dao.SysRoleFuncMapper;
import com.hanqi.entity.SysRoleFunc;
import com.hanqi.service.SysRoleFuncService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class SysRoleFuncServiceImpl extends ServiceImpl<SysRoleFuncMapper, SysRoleFunc> implements SysRoleFuncService {

    @Override
    public List<Map<String, Object>> funcsByMenuIdWithRoleId(String menuId, String roleId) {
        List<Map<String, Object>> list = baseMapper.funcsByMenuIdWithRoleId(roleId, menuId);
        for (Map<String, Object> map : list) {
            if (map.get("checked").equals("1")) {
                map.put("checked", true);
            } else {
                map.put("checked", false);
            }
        }
        return list;
    }

    @Override
    public boolean insertAuth(String menuFuncId, String roleId) {
        return baseMapper.insertAuth(menuFuncId, roleId) > 0;
    }

    @Override
    public boolean removeAuth(String menuFuncId, String roleId) {
        return baseMapper.removeAuth(menuFuncId, roleId) > 0;
    }
}
